<?php
namespace Store\Controller;

class UserController extends CommonController
{

    public function updatePassword()
    {
        if (IS_POST) {
            $data = I('post.');
            $user = D('User');
            $userID = isStoreLogin();
            $info = $user->where('user_id = ' . $userID)->find();
            if ($info['password'] != md5($data['old_password'])){
                $this->error('原密码不对');
            }
            $data['user_id'] = $userID;
            $data['password'] = md5($data['password']);
            $result = $user->update($data);
            if (false !== $result) {
                showDialog('修改密码成功', U('store/index/index'), 'succ');
            } else {
                $error = $user->getError();
                showDialog(empty($error) ? '未知错误' : $error, '', 'error');
            }
        } else {
            $this->display();
        }
    }
}